import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


public class FileWritingDemo {
	
	public static void main(String[] args) {
		
	
		
		String s="Hello this is my first io session ";

		try {
			
			FileOutputStream fileOutputStream= new FileOutputStream("C:/javaprg/temp.txt");
			fileOutputStream.write(s.getBytes());
			fileOutputStream.flush();
			fileOutputStream.close();
			System.out.println("File written successfully");
			
			
			
			FileInputStream fileInputStream= new FileInputStream("C:/javaprg/temp.txt");
	 int b=0;
	    while ((b=fileInputStream.read())!=-1) {
	    	System.out.print((char) b);
			
		}
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


		
		
	}

}
